home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
UTILITY
/
DO1002.ARJ
/
GOSUB.SCR
< prev
next >
Wrap
Text File
|
1991-12-29
|
2KB
|
64 lines
.pg wi full clr cy
COMMAND NAME»gray«: »%t« GosubLabel »ye«
/GOSUB {Label} [{param1} {param2} ... ]
/cw
The »%t«GosubLabel»#« command executes a section of the script
until a »%t«ReturnfromSub»#« command is found. It then returns
execution to the line after the »%t«GosubLabel»#« Command.
The »%t«GosubLabel»#« is similar to the »%t«GotoLabel»#« command except
that execution continues until a »%t«ReturnfromSub»#« command is
found. Then the program returns to the line after the
»%t«GosubLabel»#« command.
.pg clr
»%t«GosubLabel»#« commands can be nested »ye«10»#« deep.
»wh«{Label}»#« The label defining the start of the
executed portion of the script.
Variables in »cy«{Label}»#« are expanded.
»wh«Labels are evaluated in upper case»#«.
»wh«{params}»#« Parameters which are passed to the subroutine.
These parameters are like those passed to
scripts by the »%t«ExecScript»#« command. They are
named »ye«{Label}01»#«, »ye«{Label}02»#«, etc. Parameters
are »re«deleted»#« when the »%t«ReturnFromSub»#« command is
executed.
.pg clr
Here is an example of a calculator implemented as a
»%t«GosubLabel»#« routine. Enter a pair of numbers separated by a
»wh«<space>»#« to be multiplied. Press »bo«<enter>»#« to execute each
command after it is displayed.
.pg
┌──────────────────────────┐
│ »%t«/GOSUB»ye« Parameter Passing»#« │
└──────────────────────────┘
:TOP
/SET default ""
Enter two numbers separated by a space or
press »bo«<enter>»#« to stop demonstration.
/GETS Numbers Default "Enter two numbers:" 40 UC
/IF %numbers NE "" END
/SET P @pos(%numbers,' ')
/SET num1 @cpy(%numbers,1,%p-1)
/SET num2 @cpy(%numbers,%p+1,254)
|/GOSUB Compute %num1 %num2
/GOTO TOP
:Compute
The subroutine will compute the two numbers and display the
result.
|/MATH Result "%compute01 * %compute02"
The Result is »bo« %result »#«
/RETURN
:end
.clr
»gr«NOTE»wh«:»#« If you wish to save parameters passed to a sub-routine
for use outside the sub-routine, you »re«must»#« move them to
permanent variables before the »%t«ReturnFromSub»#« command is executed.
/ENDEXEC CLEAR